package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.RecordEmailBean;
import com.yanchangapp.widget.ExpandLayout;
import com.zxl.baselib.util.formatter.BigDecimalUtils;
import com.zxl.baselib.util.ui.ResHelper;

import java.util.List;

/**
 * Created by apple on 2019-08-30.
 * description:采购记录 邮件 adapter
 */
public class RecordEmailAdapter extends BaseQuickAdapter<RecordEmailBean, BaseViewHolder> {

    public RecordEmailAdapter(int layoutResId, @Nullable List<RecordEmailBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecordEmailBean item) {
        helper.setText(R.id.tvReceiveName,item.getAddress());
        helper.setText(R.id.tvTheme,item.getSubject());
        helper.setText(R.id.tvShortContent,item.getContent());
        helper.setText(R.id.tvLongContent,item.getContent());
        ImageView ivArrow = helper.getView(R.id.ivArrowDown);
        View view = helper.getView(R.id.llContent);
        ExpandLayout expandLayout = helper.getView(R.id.expandLayout);
        if (helper.getAdapterPosition() == 0){
            expandLayout.initExpand(true,ivArrow,true);
        }else {
            expandLayout.initExpand(false,ivArrow,true);
        }
        view.setOnClickListener(v -> expandLayout.toggleExpand());
        RecyclerView rvProduct =  helper.getView(R.id.rvProduct);
        rvProduct.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
        rvProduct.setAdapter(new RdInnerProductAdapter(R.layout.item_email_inner_product,item.getRecords()));
        helper.setText(R.id.tvNumTotal, ResHelper.getString(R.string.down_order_sum,
                String.valueOf(item.getItemNum()), BigDecimalUtils.keep2Decimal(item.getMoney())));
    }
}
